package com.david.appletree;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

public class TestWidget extends AppWidgetProvider {

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

        for (int appWidgetId : appWidgetIds) {
            RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_test);
            Intent openAppIntent = new Intent(context, TestBroadCast.class);
            openAppIntent.setAction("com.david.action.test");
//            openAppIntent.putExtra(PlayService.SONG_ACTION_TYPE_KEY, PlayService.isPlaying ? PlayService.SONG_ACTION_TYPE_BIG_NOTIFY_PAUSE : PlayService.SONG_ACTION_TYPE_BIG_NOTIFY_CONTINUE);
            //打开activity时用PendingIntent.getActivity, 启动service时用getService,发送广播时使用getBroadcast
            PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 82, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            remoteViews.setOnClickPendingIntent(R.id.test, pendingIntent);
//            // 调用集合管理器对集合进行更新
            appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
        }

        super.onUpdate(context, appWidgetManager, appWidgetIds);

    }
}
